package com.example.springboot.controller;

import com.example.springboot.Service.DelSave;
import com.example.springboot.entity.Course_select_del;
import com.example.springboot.mapper.Course_select_delMapper;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
public class Course_select_delController {
    @Autowired
    private DelSave delSave;
    @Autowired
    private Course_select_delMapper course_select_delMapper;

    @GetMapping("/course_select_del")
    public List<Course_select_del> index(@RequestParam  Integer student_id ){
        List<Course_select_del> course_select_dels =  course_select_delMapper.findDel(student_id);
        course_select_dels.forEach(course_select_del -> course_select_del.setCourse(delSave.setDelCourse(course_select_del.getCourse_id())));
        return course_select_dels;
    }
    @PostMapping("/del")
    public Integer delCourse(@RequestBody Course_select_del course_select_del){
        //        添加退课表的数据
        if (delSave.insertDelC(course_select_del) == 1){
            //        删除 选课表的数据
            return course_select_delMapper.DelCourseSelect(course_select_del.getCourse_id(),course_select_del.getStudent_id());
        }else {
            return -100;
        }

    }
}
